layui.use(['form','layer','jquery','table','laydate'],function() {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery,
        table = layui.table,
        laydate = layui.laydate;

    laydate.render({
        elem: '#pullMonth'
        ,format: 'yyyy-MM' //可任意组合
        ,type: 'month'
        ,ready: function (date) {
            $(".layui-laydate").on('click', 'ul li', function () {
                $(".layui-laydate").remove();
            });
        }
        ,change: function (value) {
            $("#pullMonth").val(value);
        }
    });

    table.on('toolbar(table)', function(obj){
        var tableCheckData = table.checkStatus(obj.config.id);
        tableToolbarEnvent(obj);
        switch(obj.event){
            case 'pull':
                var index = layui.layer.open({
                    type: 1
                    ,title: "选择拉取数据的月份"
                    ,content: $('#dateDiv')
                    ,area: ['300px', '170px']
                    ,btn: ["确定","取消"]
                    ,yes: function(index, layero){
                        if($("#pullMonth").val() == ''){
                            layer.msg("请选择要拉取数据的月份");
                            return;
                        }
                        layui.layer.close(index);
                        var indx;
                        $.ajax({
                            url: "/manage/work_order_status/pull",
                            type: "post",
                            data: $("#pullMonth").val(),
                            dataType: "json",
                            async: true,
                            contentType: "application/json",
                            beforeSend: function () {
                                indx = top.layer.msg('数据拉取中，请稍后！', {icon: 16, time: false, shade: 0.8});
                            },
                            success: function (d) {
                                if(d.code == '200'){
                                    layer.msg('数据拉取成功',{icon:1});
                                    table.reload('table');
                                }else{
                                    layer.msg('数据拉取失败！'+d.msg,{icon:2})
                                }
                                top.layer.close(indx);
                            }
                            ,error: function () {
                                top.layer.close(indx);
                                alert("数据拉取失败！");
                            }
                        })
                    }
                })
                break;
        };
    });
})